/**
 * @author PerronJones
 */

/*
 * ----------------------------------------------------------------------------
 * ----------------------------------------------------------------------------
 * ----------------------DATA AQUISITION FUNCTIONS-----------------------------
 * ----------------------------------------------------------------------------
 * ----------------------------------------------------------------------------
 */

function createTile(image, name, width, height, yards, colorID, amountLeft) {

	return $.ajax({
		url : "tile",
		context : document.body,
		type : 'POST',
		dataType : "json",
		data : {
			'image' : image,
			'name' : name,
			'width' : width,
			'height' : height,
			'yards' : yards,
			'colorID' : colorID,
			'amountLeft' : amountLeft
		},
		async : false,
		success : function(data) {
			console.log("Data Success");
			console.log(data);

		},
		error : function(jqXHR, textStatus, errorThrown) {
			console.log("Status: " + textStatus);
			console.log("Error: " + errorThrown);
		}
	});

}

function readAllTiles() {

	return $.ajax({
		url : "tile",
		context : document.body,
		async : false,
		dataType : "json",
		success : function(data) {
			console.log("dataFunctions.js")
			console.log("Data Success");
			console.log(data);
		},
		error : function(jqXHR, textStatus, errorThrown) {
			console.log("Status: " + textStatus);
			console.log("Error: " + errorThrown);
		}
	});

}

function readTile(tileID) {

	return $.ajax({
		url : "tile/" + tileID,
		context : document.body,
		dataType : "json",
		async : false,
		success : function(data) {
			console.log("Data Success");
			console.log(data);

		},
		error : function(jqXHR, textStatus, errorThrown) {
			console.log("Status: " + textStatus);
			console.log("Error: " + errorThrown);
		}
	});

}

function updateTile(tileID, image, name, width, height, yards, colorID, amountLeft) {

	return $.ajax({
		url : "tile/" + tileID,
		context : document.body,
		type : 'POST',
		headers : {
			'X-HTTP-Method-Override' : 'PUT'
		},
		type : 'POST',
		dataType : "json",
		data : {
			'image' : image,
			'name' : name,
			'width' : width,
			'height' : height,
			'yards' : yards,
			'colorID' : colorID,
			'amountLeft' : amountLeft
		},
		async : false,
		success : function(data) {
			console.log("Data Success");
			console.log(data);

		},
		error : function(jqXHR, textStatus, errorThrown) {
			console.log("Status: " + textStatus);
			console.log("Error: " + errorThrown);
		}
	});

}

function deleteTile(tileID) {

	return $.ajax({
		url : "tile/" + tileID,
		context : document.body,
		type : 'DELETE',
		dataType : "json",
		async : false,
		success : function(data) {
			console.log("Data Success");
			console.log(data);

		},
		error : function(jqXHR, textStatus, errorThrown) {
			console.log("Status: " + textStatus);
			console.log("Error: " + errorThrown);
		}
	});

}
